﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.CopsBanditsUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Events.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import Modules.bandits.*;
    import ZLocalization.*;
    import Display.ValentineUI.*;
    import Classes.doobers.*;
    import flash.text.*;
    import Display.aswingui.*;

    public class BanditsCell extends AchievementsCell {

        public static const BANDIT_ICON_HEIGHT:int = 100;
        public static const BANDIT_CELL_WIDTH:int = 145;
        public static const BANDIT_CELL_HEIGHT:int = 308;

        protected var m_bandit:BanditData;
        protected var m_meetsRequirement:Boolean = false;

        public function BanditsCell(_arg1:int=0){
            super(_arg1);
            this.addEventListener(MouseEvent.ROLL_OVER, this.onRollOver, false, 0, true);
        }
        override public function setCellValue(_arg1):void{
            var _local2:int;
            var _local3:int;
            this.m_bandit = (_arg1 as BanditData);
            if (this.m_bandit.id == -1){
                m_dummy = true;
            } else {
                _local2 = this.m_bandit.requiredPoliceLevel;
                _local3 = BanditUtil.getPoliceStationLevel();
                if (_local2 <= _local3){
                    this.m_meetsRequirement = true;
                };
            };
            this.buildCell();
            this.loadAssets();
        }
        override protected function buildCell():void{
            m_iconPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            m_headerPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            m_rewardPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            m_claimPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.buildBackground();
            if (m_dummy == false){
                this.makeHeaderPanel();
                this.makeIconPanel();
                this.makeClaimPanel();
                this.makeRewardPanel();
            };
            ASwingHelper.prepare(this);
        }
        override protected function buildBackground():void{
            var _local1:DisplayObject = (new (CopsDialog.assetDict["police_rewardBG_left_blue"])() as DisplayObject);
            var _local2:DisplayObject = (new (CopsDialog.assetDict["police_rewardBG_left_disabled"])() as DisplayObject);
            var _local3:DisplayObject = (new (CopsDialog.assetDict["police_rewardBG_left_white"])() as DisplayObject);
            var _local4:DisplayObject = (new (CopsDialog.assetDict["police_rewardBG_center_blue"])() as DisplayObject);
            var _local5:DisplayObject = (new (CopsDialog.assetDict["police_rewardBG_center_disabled"])() as DisplayObject);
            var _local6:DisplayObject = (new (CopsDialog.assetDict["police_rewardBG_center_white"])() as DisplayObject);
            var _local7:DisplayObject = (new (CopsDialog.assetDict["police_rewardBG_right_blue"])() as DisplayObject);
            var _local8:DisplayObject = (new (CopsDialog.assetDict["police_rewardBG_right_disabled"])() as DisplayObject);
            var _local9:DisplayObject = (new (CopsDialog.assetDict["police_rewardBG_right_white"])() as DisplayObject);
            var _local10:int = (m_position % BanditsPanel.BANDITS_PER_PAGE);
            if (_local10 == 1){
                m_bg = _local3;
            } else {
                if (_local10 == 2){
                    m_bg = _local6;
                } else {
                    if (_local10 == 3){
                        m_bg = _local6;
                    } else {
                        m_bg = _local9;
                    };
                };
            };
            ASwingHelper.setBackground(this, m_bg);
            ASwingHelper.setForcedSize(this, new IntDimension(BANDIT_CELL_WIDTH, BANDIT_CELL_HEIGHT));
        }
        override protected function makeHeaderPanel():void{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local2:uint = EmbeddedArt.darkBlueTextColor;
            if (!this.m_meetsRequirement){
                _local2 = EmbeddedArt.lightGrayTextColor;
            };
            var _local3:String = this.m_bandit.name;
            var _local4:AssetPane = ASwingHelper.makeMultilineCapsText(_local3, 130, EmbeddedArt.TITLE_FONT, TextFormatAlign.CENTER, 13, _local2);
            _local1.append(_local4);
            m_headerPanel.append(_local1);
            ASwingHelper.setForcedHeight(m_headerPanel, 30);
            this.appendAll(ASwingHelper.verticalStrut(5), m_headerPanel);
        }
        override protected function makeClaimPanel():void{
            var _local5:int;
            var _local6:int;
            var _local7:LocalizationObjectToken;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local2:uint = EmbeddedArt.darkBlueTextColor;
            var _local3 = "";
            if (!this.m_meetsRequirement){
                _local5 = this.m_bandit.requiredPoliceLevel;
                _local3 = ZLoc.t("Dialogs", "StationRequirementsText", {level:_local5});
                _local2 = EmbeddedArt.lightGrayTextColor;
            } else {
                _local6 = this.m_bandit.requiredCops;
                _local7 = ZLoc.tk("Dialogs", "Officer", "", _local6);
                _local3 = ZLoc.t("Dialogs", "CopRequirementsText", {
                    numCops:_local6,
                    officer:_local7
                });
            };
            var _local4:AssetPane = ASwingHelper.makeMultilineText(_local3, 130, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.CENTER, 10, _local2);
            _local1.appendAll(ASwingHelper.verticalStrut(5), _local4);
            ASwingHelper.setForcedHeight(_local1, 30);
            m_claimPanel.append(_local1);
            this.append(m_claimPanel);
        }
        override protected function makeRewardPanel():void{
            var _local4:DisplayObject;
            var _local5:DisplayObject;
            var _local6:MarginBackground;
            var _local7:ASColor;
            var _local8:DisplayObject;
            var _local9:JLabel;
            var _local10:JPanel;
            var _local11:DisplayObject;
            var _local12:JLabel;
            var _local13:JPanel;
            var _local14:DisplayObject;
            var _local15:JLabel;
            var _local16:JPanel;
            var _local17:DisplayObject;
            var _local18:JLabel;
            var _local19:JPanel;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            var _local2:uint = EmbeddedArt.darkBlueTextColor;
            if (!this.m_meetsRequirement){
                _local2 = EmbeddedArt.lightGrayTextColor;
            };
            var _local3:JLabel = ASwingHelper.makeLabel(ZLoc.t("Dialogs", "BanditsUI_rewards"), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 15, _local2);
            _local1.appendAll(_local3, ASwingHelper.verticalStrut(5));
            if (this.m_bandit.rewardItems.length > 0){
                _local4 = (new (CopsDialog.assetDict["rewardCard_locked"])() as DisplayObject);
                _local5 = (new (CopsDialog.assetDict["rewardCard_unlocked"])() as DisplayObject);
                _local6 = new MarginBackground(_local5, new Insets(0, 26, 6, 26));
                if (!this.m_meetsRequirement){
                    _local6 = new MarginBackground(_local4, new Insets(0, 26, 6, 26));
                };
                m_rewardPanel.setBackgroundDecorator(_local6);
            } else {
                _local7 = new ASColor(EmbeddedArt.darkBlueTextColor);
                if (!this.m_meetsRequirement){
                    _local7 = new ASColor(EmbeddedArt.lightGrayTextColor);
                };
                if (this.m_bandit.rewardDooberTotals[Doober.DOOBER_XP] != null){
                    _local8 = (new EmbeddedArt.smallXPIcon() as DisplayObject);
                    _local9 = new JLabel(ZLoc.t("Dialogs", "NumXP", {num:this.m_bandit.rewardDooberTotals[Doober.DOOBER_XP]}));
                    _local9.setFont(ASwingHelper.getBoldFont(14));
                    _local9.setForeground(_local7);
                    _local10 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
                    _local10.appendAll(ASwingHelper.horizontalStrut(15), new AssetPane(_local8));
                    _local10.appendAll(ASwingHelper.horizontalStrut(5), _local9);
                    m_rewardPanel.append(_local10);
                };
                if (this.m_bandit.rewardDooberTotals[Doober.DOOBER_GOODS] != null){
                    _local11 = (new EmbeddedArt.smallGoodsIcon() as DisplayObject);
                    _local12 = new JLabel(ZLoc.t("Dialogs", "NumGoods", {num:this.m_bandit.rewardDooberTotals[Doober.DOOBER_GOODS]}));
                    _local12.setFont(ASwingHelper.getBoldFont(14));
                    _local12.setForeground(_local7);
                    _local13 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
                    _local13.appendAll(ASwingHelper.horizontalStrut(15), new AssetPane(_local11));
                    _local13.appendAll(ASwingHelper.horizontalStrut(5), _local12);
                    m_rewardPanel.append(_local13);
                };
                if (this.m_bandit.rewardDooberTotals[Doober.DOOBER_COIN] != null){
                    _local14 = (new EmbeddedArt.smallCoinIcon() as DisplayObject);
                    _local15 = new JLabel(ZLoc.t("Dialogs", "NumCoins", {num:this.m_bandit.rewardDooberTotals[Doober.DOOBER_COIN]}));
                    _local15.setFont(ASwingHelper.getBoldFont(14));
                    _local15.setForeground(_local7);
                    _local16 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
                    _local16.appendAll(ASwingHelper.horizontalStrut(15), new AssetPane(_local14));
                    _local16.appendAll(ASwingHelper.horizontalStrut(5), _local15);
                    m_rewardPanel.append(_local16);
                };
                if (this.m_bandit.rewardDooberTotals[Doober.DOOBER_ENERGY] != null){
                    _local17 = (new EmbeddedArt.smallEnergyIcon() as DisplayObject);
                    _local18 = new JLabel(ZLoc.t("Dialogs", "NumEnergy", {num:this.m_bandit.rewardDooberTotals[Doober.DOOBER_ENERGY]}));
                    _local18.setFont(ASwingHelper.getBoldFont(14));
                    _local18.setForeground(_local7);
                    _local19 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
                    _local19.appendAll(ASwingHelper.horizontalStrut(15), new AssetPane(_local17));
                    _local19.appendAll(ASwingHelper.horizontalStrut(5), _local18);
                    m_rewardPanel.append(_local19);
                };
            };
            ASwingHelper.setForcedHeight(m_rewardPanel, 100);
            _local1.append(m_rewardPanel);
            this.appendAll(ASwingHelper.verticalStrut(5), _local1);
        }
        override protected function makeIconPanel():void{
            ASwingHelper.setForcedHeight(m_iconPanel, BANDIT_ICON_HEIGHT);
            this.appendAll(ASwingHelper.verticalStrut(5), m_iconPanel);
        }
        override protected function loadAssets():void{
            if (m_dummy == false){
                if (this.m_bandit.wasCaptured()){
                    if (this.m_bandit.caughtUrl){
                        m_iconLoader = LoadingManager.load(Global.getAssetURL(this.m_bandit.caughtUrl), this.onIconLoad, LoadingManager.PRIORITY_HIGH);
                    };
                } else {
                    if (this.m_bandit.portraitUrl){
                        m_iconLoader = LoadingManager.load(Global.getAssetURL(this.m_bandit.portraitUrl), this.onIconLoad, LoadingManager.PRIORITY_HIGH);
                    };
                };
                if (this.m_bandit.rewardItems.length > 0){
                    m_rewardLoader = LoadingManager.load(Global.gameSettings.getImageByName(this.m_bandit.rewardItems[0], "icon"), onRewardLoad, LoadingManager.PRIORITY_HIGH);
                };
            };
        }
        override protected function onIconLoad(_arg1:Event):void{
            if (((m_iconLoader) && (m_iconLoader.content))){
                m_icon = m_iconLoader.content;
            };
            placeIcon();
            setGridListCellStatus(m_gridList, false, m_index);
        }
        override protected function placeReward():void{
            var _local1:Sprite = new Sprite();
            _local1.addChild(m_reward);
            m_rewardPanel.addChild(_local1);
            if (!this.m_meetsRequirement){
                _local1.alpha = 0.5;
            };
            _local1.x = ((m_rewardPanel.width / 2) - (m_reward.width / 2));
            _local1.y = ((m_rewardPanel.height / 2) - (m_reward.height / 2));
            ASwingHelper.prepare(this);
        }
        protected function onRollOver(_arg1:MouseEvent):void{
            dispatchEvent(new GenericObjectEvent(GenericObjectEvent.REFRESH_BANDIT_INFO, this.m_bandit.description, true));
        }

    }
}//package Display.CopsBanditsUI 
